package com.eshop.modules.security.security;

import org.springframework.security.config.annotation.SecurityBuilder;
import javax.servlet.Filter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;

public class TokenConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity>
{
    private final TokenUtil tokenUtil;
    
    public TokenConfigurer(final TokenUtil tokenUtil) {
        this.tokenUtil = tokenUtil;
    }
    
    public void configure(final HttpSecurity http) {
        final TokenFilter customFilter = new TokenFilter(this.tokenUtil);
        http.addFilterBefore((Filter)customFilter, (Class)UsernamePasswordAuthenticationFilter.class);
    }
}
